/**
 * Created with JetBrains PhpStorm.
 * User: power_yin
 * Date: 13-10-12
 * Time: 上午11:16
 * To change this template use File | Settings | File Templates.
 */
//http://www.htcrm.net/public/api/qqStatus.php?qqNumber=80871901
(function(xf, $){
    xf.CustomerServiceList.initBar = function(qqNumberWrap, map){
        var qqNumberWrap_jQ = $(qqNumberWrap);
        qqNumberWrap_jQ.children('li').each(function(index, li){
            $(li).find('.top-bar>.name>a').attr('href', 'http://wpa.qq.com/msgrd?v=3&uin='+ map[index].qq +'&site=qq&menu=yes').html(map[index].name).end().
                find('.email').html(map[index].email);
        });
    };
    xf.CustomerServiceList.updateQQStatus = function(qqNumberWrap, map){
        var qqNumberWrap_jQ = $(qqNumberWrap);
        var i = 0;
        function callSelf(item){
            _checkStatus(item.qq, function(data, type, xhr){
                if(data.status){
                    qqNumberWrap_jQ.find(item.tag + '>a').html('在线').addClass('qq-online');
                }else{
                    qqNumberWrap_jQ.find(item.tag + '>a').html('不在线').addClass('qq-outline');
                }
                /* 防止多读取 导致 报错 */
                if(i>=map.length){
                    return;
                }
                callSelf(map[i++]);
            });
        }
        callSelf(map[i]);
        function _checkStatus(qq, callback){
            $.ajax({
                type: "GET",
                url: "./checkQQStatus.php?idcode=" + parseInt(Math.random() * 100000),
                data: {qqNumber: qq},
                dataType: "json",
                qqNumber : qq,
                success: callback
            });
        }
    };
})(XF || (XF = {}), jQuery );